﻿using System.Globalization;
using System.Reflection;
using log4net;
using log4net.Config;

namespace PD.WorkflowLibrary
{
    /// <summary>
    /// Represents a class that logs the exceptions.
    /// </summary>
    public sealed class Logger
    {
        /// <summary>
        /// An instance of the logger.
        /// </summary>
        private static ILog logger;

        /// <summary>
        /// Prevents a default instance of the <see cref="Logger"/> class from being created.
        /// </summary>
        private Logger()
        {
        }

        /// <summary>
        /// Gets the instance of the logger.
        /// </summary>
        public static ILog Instance
        {
            get
            {
                if (logger == null)
                {
                    logger = LogManager.GetLogger(typeof(Logger));
                    StartLogging();
                }

                return logger;
            }
        }

        /// <summary>
        /// Starts the logging.
        /// </summary>
        private static void StartLogging()
        {
            XmlConfigurator.Configure();
            LogVersion();
        }

        /// <summary>
        /// Logs the version.
        /// </summary>
        private static void LogVersion()
        {
            Instance.Info(string.Format(
                CultureInfo.CurrentCulture,
                Resources.WorkflowVersion,
                Assembly.GetExecutingAssembly().GetName().Version));
        }
    }
}